package oj;

public class LC61 {
    public ListNode rotateRight(ListNode head, int k) {
        if(k==0 || head==null || head.next==null) return head;
        int len=0;
        ListNode tail=null;
        for(ListNode node=head;node!=null;node=node.next){
            tail=node;
            len++;
        }
        if(k%len==0) return head;
        int m=(k%len);
        ListNode node=head;
        for(int i=0;i<len-m-1;i++){
            node=node.next;
        }
        tail.next=head;
        head=node.next;
        node.next=null;
        return head;

    }
}

